package com.company;
import java.util.Random;
import java.util.Scanner;
public class MoraGame {
    public static void main(String[] args) {
        int num = 0;//代表玩家获胜次数
        int same = 0;//代表与电脑平局次数
        System.out.println("程序已经开启");
        System.out.println("剪刀  石头 布 ");
        Scanner input = new Scanner(System.in);
        for (int i = 1; i <= 5; i++) {
            System.out.println("这是第" + i + "局");
            String get = input.next();//接收玩家输入的字符
            int randomNumber = new Random().nextInt(3) + 1;
            //判断用户输入的字符
            if (get.equals("剪刀")) {
                //判断谁输谁赢
                if (randomNumber == 1) {
                    System.out.println("电脑出的是剪刀");
                    System.out.println("平");
                    same++;
                } else if (randomNumber == 2) {
                    System.out.println("电脑出的是石头");
                    System.out.println("你输了");
                } else if (randomNumber == 3) {
                    System.out.println("电脑出的是布");
                    System.out.println("你赢了");
                    num++;
                }
            }else if (get.equals("石头")) {
                //再次判断谁输谁赢
                if (randomNumber == 1) {
                    System.out.println("电脑出的是剪刀");
                    System.out.println("你赢了");
                    num++;
                } else if (randomNumber == 2) {
                    System.out.println("电脑出的是石头");
                    System.out.println("平");
                    same++;
                } else if (randomNumber == 3) {
                    System.out.println("电脑出的是布");
                    System.out.println("你输了");
                }
                else if (get.equals("布")) {
                    if (randomNumber == 1) {
                        System.out.println("电脑出的是剪刀");
                        System.out.println("你输了");
                    } else if (randomNumber == 2) {
                        System.out.println("电脑出的是石头");
                        System.out.println("你赢了");
                        num++;
                    } else if (randomNumber == 3) {
                        System.out.println("电脑出的是布");
                        System.out.println("平");
                        same++;
                    }else{
                        System.out.println("输入出错啦！");
                    }

                }
            }


        }
        System.out.println("本次游戏您赢了"+num+"局,平了"+same+"局");
        int computer=5-num-same;//计算出电脑胜利的局数
        if(num==computer){
            System.out.println("和局了");
        }else if(num>computer){
            System.out.println("您赢了");
        }else{
            System.out.println("您输了");
        }
    }
}
